package logic

import (
	"context"
	"database/sql"

	"gitee.com/gao-deguang/easy-chat/apps/social/rpc/internal/svc"
	"gitee.com/gao-deguang/easy-chat/apps/social/rpc/social"
	"gitee.com/gao-deguang/easy-chat/apps/social/socialmodels"
	"gitee.com/gao-deguang/easy-chat/pkg/wuid"

	"github.com/zeromicro/go-zero/core/logx"
)

type GroupCreateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGroupCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GroupCreateLogic {
	return &GroupCreateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 群业务
func (l *GroupCreateLogic) GroupCreate(in *social.GroupCreateReq) (*social.GroupCreateResp, error) {
	// todo: add your logic here and delete this line
	Group := &socialmodels.Groups{
		Id:   wuid.GenUid(l.svcCtx.Config.Mysql.DataSource),
		Name: in.Name,
		Icon: sql.NullString{
			String: in.Icon,
			Valid:  true,
		},
		Status: sql.NullInt64{
			Int64: int64(in.Status),
			Valid: true,
		},
		CreatorUid: in.CreatorUid,
	}

	_, err := l.svcCtx.GroupsModel.Insert(l.ctx, Group)

	return &social.GroupCreateResp{}, err
}
